<template>
  <div class="login-wrapper">
    <div class="login-logo"></div>
    <div class="login-form">
      <input type="text" placeholder="用户名" v-model="username" autocomplete />
      <input type="password" placeholder="密码" v-model="password" autocomplete />
      <button type="submit" class="primary" @click.prevent="handleLogin">
        登录
      </button>
    </div>
  </div>
</template>

<script>
import loginApi from './../api/login'
export default {
  name: 'Login',
  data() {
    return {
      username: '',
      password: ''
    }
  },
  methods: {
    async handleLogin() {
      const params = {
        username: this.username,
        password: this.password
      }
      try {
        const res = await loginApi.login(params)
        if (res.code === 200) {
          this.$router.push('/admin/home')
          this.$Message.success(res.message)
        } else {
          this.$Message.error(res.message)
        }
      } catch (err) {
        console.log(err)
      }
    }
  }
}
</script>
